﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shove.Web.UI;

public partial class UserControls_EditCustomerInfo : UCBase
{
    public UserControls_EditCustomerInfo()
    {
        Name = "修改会员信息";

        swpas = new ShoveWebPartAttribute[12];

        swpas[0] = new ShoveWebPartAttribute_Int("控件宽度", "1,1004", 759, "控件宽度");
        swpas[1] = new ShoveWebPartAttribute_Int("导航单元格高度", "1,500", 23, "导航单元格高度");
        swpas[2] = new ShoveWebPartAttribute_Int("导航单元格宽度", "1,600", 139, "导航单元格宽度");
        swpas[3] = new ShoveWebPartAttribute_Int("标题行高", "1,200", 23, "标题行高");
        swpas[4] = new ShoveWebPartAttribute_Int("文本框宽度", "1,500", 120, "文本框宽度");

        swpas[5] = new ShoveWebPartAttribute_Color("控件边框颜色", "#E7C890", "控件边框颜色");
       
        swpas[6] = new ShoveWebPartAttribute_Image("导航背景图片1", "", "images/UserControls/bg_gold_23.jpg", "导航背景图片1");
        swpas[7] = new ShoveWebPartAttribute_Image("导航背景图片2", "", "images/UserControls/bg_gold_23_2.jpg", "导航背景图片2");

        swpas[8] = new ShoveWebPartAttribute_Text("导航文本样式", "", "black12", "导航文本样式");
        swpas[9] = new ShoveWebPartAttribute_Text("用户名CSS样式", "", "black12", "用户名CSS样式");
        swpas[10] = new ShoveWebPartAttribute_Text("提示文本样式", "", "help12", "提示文本样式");
        swpas[11] = new ShoveWebPartAttribute_Text("文本框样式", "", "in_p2", "文本框样式");
    }

    private void Initlayout()
    {
        //tabctr.Width = swpAttributes[0];
        //tabctr.BgColor = swpAttributes[5];

        //tdsign.Width = swpAttributes[2];
        //tdsign.Height = swpAttributes[1];
        //tdsign.Style.Add("background-image", "url('" + swpAttributes[6] + "')");
        //tdsign.Attributes.Add("class", swpAttributes[8]);

        //tdspace.Style.Add("background-image", "url('" + swpAttributes[7] + "')");

        tdname.Attributes.Add("class", swpAttributes[9]);
        tdname1.Attributes.Add("class", swpAttributes[10]);

        tdrealName.Attributes.Add("class", swpAttributes[9]);
        tdrealName1.Attributes.Add("class", swpAttributes[10]);
        txtUserName.Attributes.Add("class", swpAttributes[11]);
        txtUserName.Width = new Unit(swpAttributes[4]);

        tdsex.Attributes.Add("class", swpAttributes[9]);
        tdsex1.Attributes.Add("class", swpAttributes[10]);

        tddate.Attributes.Add("class", swpAttributes[9]);
        txtBirthday.Attributes.Add("class", swpAttributes[11]);
        txtBirthday.Width = new Unit(swpAttributes[4]);

        tdemail.Attributes.Add("class", swpAttributes[9]);
        tdemail1.Attributes.Add("class", swpAttributes[10]);
        txtEmail.Attributes.Add("class", swpAttributes[11]);
        txtEmail.Width = new Unit(swpAttributes[4]);

        tdmobil.Attributes.Add("class", swpAttributes[9]);
        tdmobil1.Attributes.Add("class", swpAttributes[10]);
        txtMobile.Attributes.Add("class", swpAttributes[11]);
        txtMobile.Width = new Unit(swpAttributes[4]);

        tdtel.Attributes.Add("class", swpAttributes[9]);
        tdtel1.Attributes.Add("class", swpAttributes[10]);
        txtTel.Attributes.Add("class", swpAttributes[11]);
        txtTel.Width = new Unit(swpAttributes[4]);

        tdcode.Attributes.Add("class", swpAttributes[9]);
        tdcode1.Attributes.Add("class", swpAttributes[10]);
        txtZipCode.Attributes.Add("class", swpAttributes[11]);
        txtZipCode.Width = new Unit(swpAttributes[4]);
        tdaddress.Attributes.Add("class", swpAttributes[9]);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
       Initlayout();
       LoadData();

       AjaxPro.Utility.RegisterTypeForAjax(typeof(Ajax.ShopCustomer));
       ddlProvince.Attributes.Add("onchange", "ddlProvinceChange(this)");
    }

    /// <summary>
    /// 加载会员信息
    /// </summary>
    private void LoadData()
    {
        if (_Customer == null)
        {
            Response.Redirect("Default.aspx?PN=Login");
        }
        else
        {
            //加载会员基本信息
            lbUserName.Text = _Customer.CustomerNO;
            txtUserName.Text = _Customer.CustomerName;

            if (_Customer.Sex == "男")
            {
                rblSex.SelectedIndex = 0;
            }
            else
            {
                rblSex.SelectedIndex = 1;
            }
 
            txtBirthday.Text = _Customer.Birthday.ToString("yyyy-MM-dd");
            txtEmail.Text = _Customer.Email;
            txtTel.Text =_Customer.Tel;
            txtMobile.Text = _Customer.Mobile;
            txtZipCode.Text = _Customer.PostCode;

            LoadProvince();
            ddlProvince.SelectedValue = _Customer.ProvinceID.ToString();
            LoadCity(Shove._Convert.StrToInt(ddlProvince.SelectedValue,0));

            ddlCity.SelectedValue = _Customer.CityID.ToString();
            txtAddress.Text = _Customer.Address;
        }
    }

    private void LoadProvince()
    {
        ddlProvince.DataSource = BLL.CommBLL.GetProvince();
        ddlProvince.DataTextField = "Name";
        ddlProvince.DataValueField = "ID";
        ddlProvince.DataBind();
    }

    private void LoadCity(int ProvinceID)
    {
        ddlCity.Items.Clear();

        ddlCity.DataSource = BLL.CommBLL.GetCity(ProvinceID);
        ddlCity.DataTextField = "Name";
        ddlCity.DataValueField = "ID";
        ddlCity.DataBind();
    }

    /// <summary>
    /// 确定修改
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ibOK_Click1(object sender, ImageClickEventArgs e)
    {
        if(Page.IsValid)
        {
            if (!Shove._String.Valid.isEmail(txtEmail.Text))
            {
                Shove._Web.JavaScript.Alert(this.Page, "Email格式不对！");

                return;
            }

            DAL.Tables.tbl_Customer Customer = new DAL.Tables.tbl_Customer();
            Customer.CustomerName.Value = txtUserName.Text.Trim();
            Customer.Sex.Value = rblSex.SelectedValue;
            Customer.Birthday.Value = Shove._Convert.StrToDateTime(txtBirthday.Value.ToString(),DateTime.Now.ToString("yyyy-MM-dd"));

            Customer.Tel.Value = txtTel.Text.Trim();
            Customer.Mobile.Value = txtMobile.Text.Trim();
            Customer.Email.Value = txtEmail.Text.Trim();

            Customer.PostCode.Value = txtZipCode.Text.Trim();
            Customer.CityID.Value = Shove._Convert.StrToInt(Request.Form[ddlCity.UniqueID], 0);
            Customer.Address.Value = txtAddress.Text.Trim();
           
            Customer.Update("ID=" + _Customer.ID);

            string Return = "";
            _Customer.GetCustomerInformationByID(ref Return);

            this.Response.Write("<script>alert('修改成功！');</script>");

            //LoadData();
       }
    }
}
